#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
const int N = 10000;
int n;
int s[N], b[N],sub[N];
bool use[N] = { false };
int k = 0;
void dfs(int depth,int sums,int sumb)
{
	if (depth > n)
	{
		sub[k++] = max(sums, sumb)- min(sums,sumb);
		return;
	}
	use[depth] = true;
	dfs(depth + 1, sums * s[depth], sumb + b[depth]);
	use[depth] = false;
	dfs(depth + 1, sums, sumb);
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &s[i], &b[i]);
	}
	dfs(1, 1, 0);
	printf("%d", *min_element(sub, sub + k-1));
	return 0;
}

